Ext.BLANK_IMAGE_URL='../commons/img/s.gif';//占位1px的空白图片
var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
/**
 *自定义treecombobox组建
 * 调用示例：xtype:'treecombobox'
 *          url:'#',
 *          store:[{id:'1',text:'选项'}]
 */
    Ext.define('TreeComboBox', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.treecombobox',
        url: '',
        tree: {},
        textProperty: 'text',
        valueProperty: 'id',

        initComponent: function () {
            Ext.apply(this, {
                editable: false,
                queryMode: 'local',
                select: Ext.emptyFn
            });
            this.displayField = this.displayField || 'text',
            this.treeid = Ext.String.format('tree-combobox-{0}', Ext.id());
            this.tpl = Ext.String.format('<div id="{0}"></div>', this.treeid);

            if (this.url) {
                var me = this;
                var store = Ext.create('Ext.data.TreeStore', {
                    root: { expanded: true },
                    proxy: { type: 'ajax', url: this.url }
                });
                this.tree = Ext.create('Ext.tree.Panel', {
                    rootVisible: false,
                    autoScroll: true,
                    height: 150,
                    width:me.width,
                    store: store
                });
                this.tree.on('itemclick', function (view, record) {
                    me.setValue(record);
                    me.collapse();
                });
                me.on('expand', function () {
                    if (!this.tree.rendered) {
                        this.tree.render(this.treeid);
                    }
                });
            }
            this.callParent(arguments);
        }
    });
/**
 *model 
 */    
    Ext.define('model_zxz', {
         extend: 'Ext.data.Model',
         fields: [
             {name: 'zxz_mc', type: 'string'},
             {name: 'zxz_sh',  type: 'string'},
             {name: 'zxz_xzqh',  type: 'string'},
             {name: 'yp_93',  type: 'int'},
             {name: 'yp_97',  type: 'int'},
             {name: 'yp_0',  type: 'int'},
             {name: 'zxz_zj',   type:'int'}
         ]
     });

/**
 *store 
 */     
     var store_zxz=Ext.create('Ext.data.Store', {
        model: 'model_zxz',
/*        proxy: {
            type: 'ajax',
            url: '../../Json_sy_ggxx.json',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty:'totalCount'
            }
        }*/
        groupField: 'zxz_sh',
        data : [
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567891", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567891", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567891", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567891", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567892", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567892", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567893", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567893", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                {"zxz_mc":"静态密码认证", "zxz_sh":"1234567893", "zxz_xzqh":"数字认证-1", "yp_93":"12", "yp_97":"24", "yp_0":"51", "zxz_zj":"10"},
                ]
        //autoLoad: true
     });

 /**
  *grid表格头 
  */    
     var col_zxz=[
        {xtype:'rownumberer'}, 
        {text:'中心加油站名称',width:100,dataIndex:'zxz_mc',menuDisabled:true,sortable:false},
        {text:'税号',width:100,dataIndex:'zxz_sh',menuDisabled:true,sortable:false},
        {text:'行政区划',width:100,dataIndex:'zxz_xzqh',menuDisabled:true,sortable:false},
        {text:'93#(升)',width:100,dataIndex:'yp_93',menuDisabled:true,sortable:false,summaryType: 'sum'},
        {text:'97#(升)',width:100,dataIndex:'yp_97',menuDisabled:true,sortable:false,summaryType: 'sum'},
        {text:'0#(升)',width:100,dataIndex:'yp_0',menuDisabled:true,sortable:false,summaryType: 'count'},
        {text:'总计(升)',width:100,dataIndex:'zxz_zj',menuDisabled:true,sortable:false,summaryType: 'sum'} 
     ];
 
/**
 *显示主账号创建窗口 
 */
     function showDlg_zzh_add(){ 
         var dlg_zzh_add=Ext.create('Ext.window.Window',{
             title:'离职主账号信息',
             width:700,
             height:300,
             layout:'fit',
             resizable: false,
             modal: true,
             items: [
                Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        width:700,
                        url:'#',
                        layout:'anchor',
                        defaults:{anchor:'100%' },
                        items:[{
                                xtype:'fieldcontainer',
                                layout:'hbox',
                                items:[{
                                        xtype:'textfield',
                                        fieldLabel:'主帐号名',
                                        name: 'rz_zzh',
                                        labelWidth:80,
                                        width:300,
                                        afterLabelTextTpl: required,
                                        allowBlank:false
                                },{
                                        xtype:'button',
                                        text:'获取账号信息',
                                        width:100,
                                        margin:'0 10 0 10',
                                        handler:function(){
                                                 Ext.Msg.alert('提示信息','获取主账号');
                                        }
                                }]
                        },{
                                xtype:'fieldcontainer',
                                layout:'hbox',
                                items:[{
                                        xtype:'textfield',
                                        fieldLabel:'真实姓名',
                                        name: 'rz_xm',
                                        labelWidth:80,
                                        width:300,
                                        afterLabelTextTpl: required,
                                        allowBlank:false
                                },{
                                        xtype:'treecombobox',
                                        fieldLabel:'组织机构',
                                        name: 'rz_zzbm',
                                        valueField:'id',
                                        url: '../Json_jg_combotree.json',
                                        labelWidth:80,
                                        width:300,
                                        labelAlign: 'right',
                                        afterLabelTextTpl: required,
                                        allowBlank:false
                                }]
                        },{
                                xtype:'fieldcontainer',
                                layout:'hbox',
                                items:[{
                                        xtype:'textfield',
                                        fieldLabel:'联系电话',
                                        name: 'rz_dh',
                                        labelWidth:80,
                                        width:300,
                                        afterLabelTextTpl: required,
                                        allowBlank:false
                                },{
                                        xtype:'textfield',
                                        vtype:'email',
                                        fieldLabel:'E-Mail',
                                        name: 'rz_email',
                                        labelWidth:80,
                                        width:300,
                                        labelAlign: 'right',
                                        afterLabelTextTpl: required,
                                        allowBlank:false
                                }]
                        },{
                                xtype:'fieldcontainer',
                                layout:'hbox',
                                items:[{
                                        xtype:'combo',
                                        fieldLabel:'认证方式',
                                        name: 'rz_rzfs',
                                        labelWidth:80,
                                        width:300,
                                        afterLabelTextTpl: required,
                                        editable:false,
                                        allowBlank: false,
                                        displayField:'text',
                                        valueField:'id',
                                        store: Ext.create('Ext.data.Store', {
                                                fields : ['id', 'text'],
                                                /*proxy: {
                                                    type: 'ajax',
                                                    url : '../Json_sbyf_sb_combo.json'                  
                                                }*/
                                                data : [
                                                            {"id":"1", "text":"数字认证-1"},
                                                            {"id":"2", "text":"静态密码认证-2"},
                                                            {"id":"3", "text":"令牌认证-3"},
                                                            {"id":"4", "text":"短信认证-4"}
                                                ]
                                        })
                                },{
                                        xtype:'combo',
                                        fieldLabel:'账号角色',
                                        name: 'rz_zhzt',
                                        labelWidth:80,
                                        width:300,
                                        labelAlign: 'right',
                                        afterLabelTextTpl: required,
                                        editable:false,
                                        allowBlank: false,
                                        displayField:'text',
                                        valueField:'id',
                                        store: Ext.create('Ext.data.Store', {
                                                fields : ['id', 'text'],
                                                /*proxy: {
                                                    type: 'ajax',
                                                    url : '../Json_sbyf_sb_combo.json'                  
                                                }*/
                                                data : [
                                                            {"id":"0", "text":"运维人员-0"},
                                                            {"id":"1", "text":"管理员-1"}
                                                ]
                                        })
                                }]
                    },{
                            xtype:'fieldcontainer',
                            layout:'hbox',
                            items:[{
                                    xtype:'combo',
                                    fieldLabel:'所属地市',
                                    name: 'rz_ds',
                                    labelWidth:80,
                                    width:300,
                                    afterLabelTextTpl: required,
                                    editable:false,
                                    allowBlank: false,
                                    displayField:'text',
                                    valueField:'id',
                                    store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            /*proxy: {
                                                type: 'ajax',
                                                url : '../Json_sbyf_sb_combo.json'                  
                                            }*/
                                            data : [
                                                        {"id":"311", "text":"石家庄-311"},
                                                        {"id":"315", "text":"唐山-315"},
                                                        {"id":"312", "text":"保定-312"},
                                                        {"id":"4", "text":"..........."}
                                            ]
                                    })
                            },{
                                    xtype:'combo',
                                    fieldLabel:'七类账号',
                                    name: 'rz_qlzh',
                                    labelWidth:80,
                                    width:300,
                                    labelAlign: 'right',
                                    afterLabelTextTpl: required,
                                    editable:false,
                                    allowBlank: false,
                                    displayField:'text',
                                    valueField:'id',
                                    store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            /*proxy: {
                                                type: 'ajax',
                                                url : '../Json_sbyf_sb_combo.json'                  
                                            }*/
                                            data : [
                                                        {"id":"1", "text":"营业员-1"},
                                                        {"id":"2", "text":"客服坐席-2"},
                                                        {"id":"3", "text":"渠道-3"},
                                                        {"id":"4", "text":"大客户经理-4"},
                                                        {"id":"5", "text":"业务支撑人员-5"},
                                                        {"id":"6", "text":"合作伙伴-6"},
                                                        {"id":"99", "text":"其他-99"}
                                            ]
                                    })
                            }]
                    }],
                        buttons:[{
                                text:'保存',
                                handler:function(){
                                        var f=this.up('form').getForm();
                                        if(f.isValid()){
                                                Ext.Msg.show({
                                                        title:'提示信息',
                                                        msg:'是否要提交表单？',
                                                        buttons:Ext.Msg.YESNO,
                                                        icon:Ext.Msg.INFO,
                                                        fn:function(re){
                                                                if(re=='yes'){
                                                                        alert(ret);
                                                                        f.submit();
                                                                }
                                                        }
                                                });
                                        }else{
                                                Ext.Msg.alert('提示信息','表单数据填写不完整！');
                                        }
                                }
                        },{
                                text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                                text:'关闭',handler:function(){dlg_zzh_add.close();}
                        }]
                })
             ]
         });
         dlg_zzh_add.show();
     }


     Ext.onReady(function(){
         Ext.create('Ext.panel.Panel',{
             id:'main-panel',
             //title:'员工入职工单',
             width:Ext.getBody().getWidth()-20,
             renderTo:Ext.getBody(),
             layout:{
                 type:'vbox',
                 align: 'stretch'
             },
             items:[{
                        xtype: 'grid',
                        id:'grid_zxz',
                        title:'中心站明细数据报表',
                        height:650,
                        selModel: Ext.create('Ext.selection.CheckboxModel', { mode: "SIMPLE" }),
                        columns: col_zxz,            
                        store: store_zxz,
                        features: [{
                            groupHeaderTpl: '{name}',
                            ftype: 'groupingsummary',
                            startCollapsed:true
                        }],
                        dockedItems:[
                            {
                            	xtype: 'toolbar',
                            	items:[{
                            		xtype:'button',
                                    text:'查询',
                                    margin:'10 10 0 10',
                                    width:120,
                                    handler:function(){
                                            Ext.Msg.alert('提示信息','创建从账号');
                                    }
                            	},{
                            		xtype:'button',
                                    text:'主账号模板下载',
                                    margin:'10 10 0 10',
                                    width:120,
                                    handler:function(){
                                            Ext.Msg.alert('提示信息','创建从账号');
                                    }
                            	},{
                                    xtype:'combo',
                                    fieldLabel:'七类账号',
                                    name: 'rz_qlzh',
                                    labelWidth:80,
                                    width:300,
                                    labelAlign: 'right',
                                    afterLabelTextTpl: required,
                                    editable:false,
                                    allowBlank: false,
                                    displayField:'text',
                                    valueField:'id',
                                    store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            /*proxy: {
                                                type: 'ajax',
                                                url : '../Json_sbyf_sb_combo.json'                  
                                            }*/
                                            data : [
                                                        {"id":"1", "text":"营业员-1"},
                                                        {"id":"2", "text":"客服坐席-2"},
                                                        {"id":"3", "text":"渠道-3"},
                                                        {"id":"4", "text":"大客户经理-4"},
                                                        {"id":"5", "text":"业务支撑人员-5"},
                                                        {"id":"6", "text":"合作伙伴-6"},
                                                        {"id":"99", "text":"其他-99"}
                                            ]
                                    })
                            	}]
                            },{
                                xtype: 'pagingtoolbar',
                                store: store_zxz,   
                                dock: 'bottom',
                                displayInfo: true
                            }
                        ], 
                        flex: 1  
             }]
         });
     });
